package com.puman.watchtrade.fragment.home.adapter;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.puman.watchtrade.MainActivity;
import com.puman.watchtrade.R;
import com.puman.watchtrade.fragment.home.model.ComRecords;
import com.puman.watchtrade.fragment.sell.SellFragment;
import com.puman.watchtrade.fragment.sell.model.SellImgs;
import com.puman.watchtrade.fragment.sell.util.CheckImageLoaderConfiguration;
import com.puman.watchtrade.fragment.sell.util.UniversalImageLoadTool;

@SuppressLint("ResourceAsColor")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class PriceGridViewAdapter extends BaseAdapter {
	Context context;
	ComRecords comRecords;

	public PriceGridViewAdapter(Context _context, ComRecords comRecords) {
		this.context = _context;
		this.comRecords = comRecords;
	}

	@Override
	public int getCount() {
		return comRecords.comRecordList.size();
	}

	@Override
	public Object getItem(int position) {
		return comRecords.comRecordList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater layoutInflater = LayoutInflater.from(context);
		convertView = layoutInflater.inflate(R.layout.price_list_item, null);
		// se city = sellImgs.sellimgList.get(position);
		TextView orderName = (TextView) convertView
				.findViewById(R.id.order_name);
		TextView orderPrice = (TextView) convertView
				.findViewById(R.id.order_price);
		TextView rank = (TextView) convertView.findViewById(R.id.rank);
		RelativeLayout ranklayout = (RelativeLayout) convertView.findViewById(R.id.rank_relayout);
		if (comRecords.comRecordList.get(position).getOrder().equals("1")) {
			ranklayout.setBackgroundColor(MainActivity.getInstant().getResources().getColor(R.color.themeColor));
		}else {
			ranklayout.setBackgroundColor(MainActivity.getInstant().getResources().getColor(R.color.diliverLine));
		}
		if (comRecords.comRecordList.get(position).getUserName().length() > 1) {
			orderName.setText(comRecords.comRecordList.get(position).getUseNo()
					.subSequence(0, 1)+"***");
		} else {
			orderName
					.setText(comRecords.comRecordList.get(position).getUserName());
		}
		orderPrice.setText("￥"
				+ comRecords.comRecordList.get(position).getPrice());
		rank.setText(comRecords.comRecordList.get(position).getOrder() + "");
		return convertView;
	}
}
